#include <iostream>
#include "utils/git_detector.h"
#include "core/submodule_rewriter.h"

int main(int argc, char* argv[]) {
    std::string repo_path = argc > 1 ? argv[1] : ".";

    std::cout << "🚀 Git Submodule Manager (Auto Mode) Starting..." << std::endl;
    std::cout << "📁 Repository: " << repo_path << std::endl;

    // 检测 Git
    std::string git_path = GitDetector::findGitPath();
    if (git_path.empty()) return 1;

    // 创建子模块重写器
    SubmoduleRewriter rewriter(git_path);

    // 加载和重写
    if (rewriter.loadGitmodules(repo_path)) {
        std::cout << "✅ Loaded " << rewriter.getSubmodules().size() << " submodules" << std::endl;

        if (rewriter.rewriteToMirrors()) {
            std::cout << "💽 Auto-applying changes..." << std::endl;
            if (rewriter.applyChanges()) {
                std::cout << "✅ Changes applied successfully!" << std::endl;
            } else {
                std::cout << "❌ Failed to apply changes" << std::endl;
            }
        } else {
            std::cout << "ℹ️  No changes needed" << std::endl;
        }
    } else {
        std::cout << "❌ No .gitmodules found" << std::endl;
    }

    std::cout << "✨ Done!" << std::endl;
    return 0;
}
